package by.amakarevich.services.impl;

import java.util.List;

import javax.inject.Inject;

import org.apache.commons.lang3.Validate;
import org.springframework.stereotype.Service;

import by.amakarevich.dataaccess.KitDao;
import by.amakarevich.dataaccess.ProductDao;
import by.amakarevich.datamodel.Kit;
import by.amakarevich.datamodel.Product;
import by.amakarevich.services.KitService;

@Service
public class KitServiceImpl implements KitService {
	@Inject
	private KitDao kitDao;

	@Inject
	private ProductDao productDao;

	@Override
	public void createNewKit(Kit kit, Product product) {
		Validate.isTrue(
				kit.getId() == null,
				"This method should be called for 'not saved yet' profile only. Use UPDATE instead");
		kit.setProduct(product);
		kitDao.insert(kit);
	}

	@Override
	public Kit get(Long id) {
		return kitDao.getById(id);
	}

	@Override
	public void updateKit(Kit kit) {
		kitDao.update(kit);
	}

	@Override
	public void removeKit(Long id) {

		kitDao.delete(id);
		productDao.delete(id);

	}

	@Override
	public void deleteAll() {
		kitDao.deleteAll();
		productDao.deleteAll();
	}
	
	@Override
	public List<Kit> getAllKit(){
		return kitDao.getAllKit();
	}
	
	@Override
	public Kit getByProductId(Product product){
		return kitDao.getByProductId(product);
	}
}
